package xyz.xtt.asset.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;

import xyz.xtt.asset.client.response.BlindBoxDetailResponse;
import xyz.xtt.asset.constants.AssetCache;
import xyz.xtt.asset.entity.TblBlindBoxDetail;
import xyz.xtt.asset.mapper.TblBlindBoxDetailMapper;
import xyz.xtt.asset.service.ITblBlindBoxDetailService;
import xyz.xtt.common.starter.cache.CacheManager;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-03-04
 */
@Service
public class TblBlindBoxDetailServiceImpl extends ServiceImpl<TblBlindBoxDetailMapper, TblBlindBoxDetail> implements ITblBlindBoxDetailService {
	@Autowired
	private CacheManager cacheManager;

	@Override
	public List<TblBlindBoxDetail> list(String goodsId) {
		LambdaQueryChainWrapper<TblBlindBoxDetail> query = new LambdaQueryChainWrapper<>(baseMapper);
		List<TblBlindBoxDetail> list = query.eq(TblBlindBoxDetail::getGoodsId, goodsId).list();
		return list;
	}

	@Override
	public List<TblBlindBoxDetail> listCache(String goodsId) {
		return cacheManager.cacheList(() -> list(goodsId), AssetCache.TBL_BLIND_BOX_DETAIL, goodsId);
	}

	@Override
	public List<BlindBoxDetailResponse> queryBlindBoxDetail(List<String> goodsId) {
		MPJLambdaWrapper<TblBlindBoxDetail> query = JoinWrappers.lambda(TblBlindBoxDetail.class).eq(TblBlindBoxDetail::getGoodsId, goodsId);
		List<BlindBoxDetailResponse> list = query.list(BlindBoxDetailResponse.class);
		return list;
	}

}
